<?php
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequestException;
require ('facebook/php-sdk-v4/autoload.php');
class FacebookLogin extends CI_Controller {
	public function __construct() {
		parent::__construct ();
		$this->config->load ( 'config' );
		$this->load->helper ( "url" );
	}
	public function index() {
		// Start session
		session_start ();
		//
		$appId = $this->config->item ( 'AppId' );
		$appSecret = $this->config->item ( 'AppSecret' );
		
		FacebookSession::setDefaultApplication ( $appId, $appSecret );
		
		//
		$helper = new FacebookRedirectLoginHelper ( 'http://localhost/ImageProcessing/index.php/ImageUpload/ImageUpload' );
		
		// Ask for user's permission
		// In Status&Review page enable the 
		// Do you want to make this app and all its live features available to the general public?
		$permission = array (
				'read_stream',//read new feeds permission
				'publish_actions',//post permission
				'user_friends',
				'read_friendlists'
		);
		
		// return the url of the web that user is redirected to
		$loginUrl = $helper->getLoginUrl ( $permission );
		
		// Facebook Session
		
		//
		redirect ( $loginUrl );
	}
	
	public function process() {
	}
}

